<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <button id="btn-onesort"   th:onclick="addBlog()">添加博客</button>
    <div>
        <input type="text" id="title" th:value="${title}" placeholder="博客标题">
        <button id="btn-onesort2" th:onclick="query()" >查询</button>
    </div>
    <table border="1">
        <tr>
            <td>标题</td>
            <td>内容</td>
            <td>分类</td>
            <td>标签</td>
            <td>评论</td>
            <td>创建人</td>
            <td>操作</td>
        </tr>
        <tr th:each="uu : ${list}">
            <td th:text="${uu.title}"></td>
            <td th:text="${uu.content}"></td>
            <td th:text="${uu.type}"></td>
            <td th:text="${uu.label}"></td>
            <td th:text="${uu.comment}"></td>
            <td th:text="${uu.createPerson}"></td>
            <td>
                <a th:onclick="deleteBlog([[${uu.id}]])">删除</a>
                <a th:href="'/blog/addpage?id='+${uu.id}">修改</a>
            </td>
        </tr>
    </table>
</body>
<script type="text/javascript" th:src="@{/js/jquery.js}"></script>

<script>
    $.ajaxSetup({
        xhrFields: {
            withCredentials: true
        },
    });
    function addBlog() {
        window.location.href = ("/blog/addpage");
    }
    function deleteBlog(uid) {
        if(confirm("确定删除吗?")){
            if(uid != null && uid != ""){
                $.ajax({
                    type : "DELETE",
                    url :"/blog/delete/"+uid,
                    contentType: "application/json",
                    success : function (res) {
                        if(res == "success"){
                            window.location.href = ("/blog/list");
                        }
                    }
                });
            }
        }
    }
    function query() {
        var title = $("#title").val();
        window.location.href = ("/blog/list?title="+title);
    }
</script>

</html>